-- ShadowSpace
-- Created by chengb Dec/30/2015
-- 阴影空间格子（阴影雕像）

-- 初始化
function initShadowSpace(self)
    self.item:removeAllChildren();

    local unrealId = self.gridData.unrealId;
    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 判断能否拾取
            if DungeonBossM.isInBossLayer() and not DungeonBossM.canPickUpTarget() then
                alert(getLocStr("pick_up_instance_target_fail"));
                return;
            end

            -- 是否穿戴了特殊视力道具
            if not DungeonEggM.hasEquipedVisionItem() then
                -- 没有穿戴特殊视力道具
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 获取格子位置
            local pos = self.gridData:getPos();

            -- 音效
            AudioM.playFx("ui_open1");

            local function okFunc()
                -- 进入前提示
                local beforeEnterTip = UnrealDungeonM.query(unrealId, "before_enter_tip");
                if type(beforeEnterTip) == "string" and beforeEnterTip ~= "" then
                    alert(beforeEnterTip);
                end

                -- 进入夹层
                DungeonActionM.go("start_unreal", pos, unrealId);
            end

            self:openBuildingView(okFunc);
        end
    end

    -- 是否穿戴了特殊视力道具
    local hasItem = DungeonEggM.hasEquipedVisionItem();

    -- 如果没有穿戴特殊视力道具，则显示一个建筑虚影
    local iconPath;
    if not hasItem then
        iconPath = getLevelItemIconPath("shadow_statue2");
    else
        iconPath = getLevelItemIconPath("shadow_statue");
    end

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);

    if self.gridData.need_prison == 1 then
        -- 初始时需要监狱图标的遮罩
        local prisonIcon = getLevelItemIconPath("prison");
        local prisonImg  = ccui.ImageView:create(prisonIcon);
        prisonImg:setName("prison_icon");

        self.item:addChild(prisonImg);
    end
end
